﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Comment_inc.aspx.cs" Inherits="newBlog.CenterInc.view_inc.Comment_inc" %>
<%@ Import Namespace="newBlog.CenterInc.tool" %>
<%@ Import Namespace="newBlog.CenterInc.Ctrltor" %>
<%  
    Response.ContentType = "application/json";
    if (Session["user_id"]==null) {
        Response.Write("{\"error\":\"您未登录禁止操作\"}");
        return;
    }
    int mode = Request.QueryString["mode"]!=null?Convert.ToInt32(Request.QueryString["mode"]):0;//判断用于什么方式1发送评论，2放入回收站，3删除评论
    isString isString = new isString();
    Comment_inc comment_Inc = new Comment_inc();
    switch(mode){
        case 1:
            string user_id = Session["user_id"].ToString();
            string article_id = Request.Form["article_id"];
            string EmailVer = Request.Form["EmailVer"];
            string conntent = Request.Form["conntent"];
            string SessionEmailVer = Session["CommentVer"]==null?"":Session["CommentVer"].ToString();
            if (isString.isEmpty(EmailVer,conntent,SessionEmailVer)) {
                Response.Write("{\"error\":\"验证码，内容不能为空\"}");
                return;
            }
            if (isString.IsRange(5,50,conntent)) {
                Response.Write("{\"error\":\"内容不能超过5~50个字符\"}");
                return;
            }

            if (!SessionEmailVer.Trim().Equals(EmailVer.Trim())) {
                Response.Write("{\"error\":\"验证码错误\"}");
                return;
            }
            if (comment_Inc.GetComment(user_id,article_id,isString.filterHtml(conntent))) {
                Response.Write("{\"error\":\"提交失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"评论成功\"}");
            Session.Remove("CommentVer");
            return;
        case 3:
            string comment_id = Request.Form["comment_id"];
            if (comment_id.Length==0) {
                Response.Write("{\"error\":\"ID不能为空\"}");
                return;
            }
            if (comment_Inc.delComment(comment_id)) {
                Response.Write("{\"error\":\"删除失败\"}");
                return;
            }
            Response.Write("{\"msg\":\"删除成功\"}");
            return;
    }
    %>